package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Collections_Demo3 {
    public static void main(String[] args) {
        //点名 点到点不会再点到 点完需要开启第二轮
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"袁天罡","孙悟空","猪八戒","沙僧","白龙马","李星云","张子凡");
        ArrayList<String> list2 = new ArrayList<>();
        for (int j = 0; j < 10; j++) {
            System.out.println("第"+"============"+(j+1)+"============"+"轮");
            //记录本轮点名的人数
            int count = list1.size();
            Random r = new Random();
            for (int i = 0; i < count; i++) {
                int index = r.nextInt(list1.size());
                //移除的元素会被打回，同时也是要点到的元素
                String name = list1.remove(index);
                list2.add(name);
                System.out.println(name);
            }
            //一轮点名结束
            //list1空了 list2中所有元素都给list1
            list1.addAll(list2);
            //list2清空
            list2.clear();
        }
    }
}
